/**
 * 创建对象方式一：
 *   基于Object的方式创建对象
 */
var student = new Object();
//属性
student.stuNo = 1001;
student.stuName = 'zhangsan';
//方法
student.show = function(){
    console.log(`学号是：${this.stuNo}，姓名是：${this.stuName}`);
}
//调用
console.log(student.stuNo);
console.log(student.stuName);
student.show();

/**
 * 创建对象方式二：
 *   使用字面量方式创建对象
 */
var teacher = {
    //属性
   "teacherNo":"9001",
   "teacherName":"lisi",
    //方法
   "print": function(){
        console.log(`编号是：${this.teacherNo}，姓名是：${this.teacherName}`);
   }
}
//调用
console.log(teacher.teacherNo);
console.log(teacher.teacherName);
teacher.print();

teacher.teacherTime = 10;
console.log(teacher.teacherTime);
teacher.test=function(){
    console.log("后创建的test方法")
}
teacher.test();

//获取参数
teacher.fn1=function(...num){
    console.log(num)
}
teacher.fn1('abc','def','21321','qwwqeq');

teacher.fn2=function(str){
    console.log("----------------")
    console.log(str);//获取形参
    console.log(arguments[0],arguments[1]);//获取实参
}
teacher.fn2('aaa','bbb');

/**
 * 创建类和对象方式三：
 *   使用构造函数方式创建类
 *   再使用new创建对象
 */
//定义类
function School(schoolName,schoolAddr){
    //属性
    this.schoolName = schoolName;
    this.schoolAddr = schoolAddr;
    //方法
    this.infoFun=function(){
        console.log(`学校名：${this.schoolName}，学校地址：${this.schoolAddr}`)
    }
}
//创建对象
var mySchool = new School('bdqn','安农大科技长廊130号');
//调用
console.log(mySchool.schoolName);
console.log(mySchool.schoolAddr);
mySchool.infoFun();

/**
 * 创建类和对象方式四：
 *   使用原型方式创建类
 *   再使用new创建对象
 */
//定义类
function MyClass(count){
    //写方式三的对象包含特征
    this.mcCount=count;
}
MyClass.prototype.mcName = "Web30";
MyClass.prototype.showInfo = function(){
    console.log("班级名为：" + this.mcName);
}
//实力化对象
var mc1 = new MyClass(30);
//mc1.mcName = "前端牛逼班";
console.log(mc1.mcName);
console.log(mc1.mcCount);
mc1.showInfo();

var mc2 = new MyClass(33);
console.log(mc2.mcName);
console.log(mc2.mcCount);
mc2.showInfo();

/**
 * 创建类和对象方式五：
 *   使用原型方式存储函数
 *   使用构造函数存储属性
 *   再使用new创建对象
 */
function KongTiao(pp){
    
    this.pingpai = pp;
}
KongTiao.prototype.zhiling = function(){
    console.log("吹冷风");
};

var gl = new KongTiao("格力");
console.log(gl.pingpai);
gl.zhiling();

var md = new KongTiao("美的");
console.log(md.pingpai);
md.zhiling();


/*
//=============================================
console.log("=============================================");
//基于Object对象
var stu1 = new Object();
stu1.info = "aaa";
var stu2 = new Object();
stu2.info = "bbb";
var stus = [stu1,stu2];
for(var i=0; i<stus.length; i++){
    console.log(stus[i].info);
}
console.log("=============================================");
//基于字面量
var tea1 = {
    info:"aaa"
}
var tea2 = {
    info:"bbb"
}
var teas = [tea1,tea2];
for(var i=0; i<teas.length; i++){
    console.log(teas[i].info);
}

console.log("=============================================");
//基于构造函数
var s1 = new School('bdqn','and');
var s2 = new School('hfxt','kjcl130');
var schools = [s1,s2];
for(var i=0; i<schools.length; i++){
    console.log(schools[i].schoolName);
    schools[i].infoFun();
}

console.log("=============================================");
//基于原型
var mcs = [mc1,mc2];
for(var i=0; i<mcs.length; i++){
    console.log(mcs[i]);
}

console.log("=============================================");

//定义宠物对象的构造函数(宠物类)
function Pet(petName,petType){
    this.petName = petName;
    this.petType = petType;
    this.petShow = function(){
        console.log(this.petName,this.petType);
    }
}
//工厂模式：封装创建宠物对象
function createPet(petName,petType){
    var pet = new Pet(petName,petType);
    //业务操作
    return pet;
}
//获取对象
var cw = createPet('旺财',"中华田园犬");

//单例模式：一般采用直接创建对象的方式来限制反复创建对象
var person;
function createPerson(){
    if(!person){
        person = new Object();
    }
    return person;
}
//获取对象
var per1 = createPerson();
per1.name = "张三";
var per2 = createPerson();
per2.fnTest=function(){
    console.log("函数");
}
console.log(per2);
per1.fnTest();
*/